#ifndef NETWORKQUICTUNHELPER_H
#define NETWORKQUICTUNHELPER_H

#include <QObject>
#include <QProcess>

class QuictunProcessThread;
struct  CreateTunnelRequest  {
    QString mGatewayAddr;
    QString  mServerAppAddr;
    QString  mLocalSocketAddr;
};
struct  CreateTunnelReply  {
    QString  mServerAppAddr;
    QString  mLocalSocketAddr;
    QString  mTunnelUuid;
    QString  mSide;
    void clear() {
        mServerAppAddr = "";
        mLocalSocketAddr = "";
        mTunnelUuid = "";
        mSide = "";
    }
    bool isEmpty() {
        return mServerAppAddr.isEmpty();
    }
};

class  NetworkQuictunHelper : public QObject
{
    Q_OBJECT
public:
    static NetworkQuictunHelper *instance();
    ~NetworkQuictunHelper();
    void sendPostCreateTunnel(const CreateTunnelRequest &req);
    void sendPutUpdateTunnel(const QString &req);
    void deleteAllTunnels();
    bool getAllTunnels();
    void stopQuictun();
    void startQuictun();
private:
    explicit NetworkQuictunHelper(QObject *parent = nullptr);
    void parsePostCreateTunnelback(QByteArray);
    QString getAvailablePort();

Q_SIGNALS:
    void signalPostCreateTunnel(CreateTunnelReply);
    void signalGetAllTunnels(QList<CreateTunnelReply>);
    void signalTransferError();
    void signalQuictunProcessFinished();
    void signaldeleteTunnels();
    void signalPlatFormTunnel(CreateTunnelReply);

private:
    static NetworkQuictunHelper *mSelf;
    QuictunProcessThread * mQuictunThread;
    CreateTunnelReply mCreateTunnelReply;
    CreateTunnelReply mPlatFormTunnel;
    QProcess *mQuictunProcess;
    bool mQuictunRunning = false;
    QString          mAvailablePort;
    QString          mOldRequest;


};

#endif // NETWORKQUICTUNHELPER_H
